package org.qf.cloudorders.controller;

import lombok.RequiredArgsConstructor;
import org.qf.cloudentity.entity.Goods;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单控制器
 */

@RestController
@RequestMapping("orders")
@RequiredArgsConstructor
public class OrderController {

    //发送REST请求
    private final RestTemplate restTemplate;


    /**
     * 下订单接口
     * @return
     */
    @GetMapping("save")
    public Map<String,Object> save(){
        String url="http://cloud-goods/goods/findById/11";
        Goods goods = restTemplate.getForObject(url, Goods.class);
        System.out.println(goods);
        return new HashMap<String, Object>(){{
            put("code",200);
            put("msg","成功");
        }};
    }
}
